<?php
include 'lanewechat.php';
include 'db.php';
/**
 * Description: 通过code换取网页授权access_token
 * 首先请注意，这里通过code换取的网页授权access_token,与基础支持中的access_token不同。
 * 公众号可通过下述接口来获取网页授权access_token。
 * 如果网页授权的作用域为snsapi_base，则本步骤中获取到网页授权access_token的同时，也获取到了openid，snsapi_base式的网页授权流程即到此为止。
 * @param $code getCode()获取的code参数
 */
$db = new Mysql( DB_HOST , DB_USER , DB_PASS , DB_NAME , null , 'utf8' );

$sql = 'select `key`,`value` from config';

$db->query( $sql );
while( $row = $db->fetch_array() ){
    $config[$row['key']] = $row['value'];
}
$where = ' where prize=0';
if( !empty( $config['keyword'] ) ){
    $keywords = explode(',',$config['keyword']);
    foreach( $keywords as $v ){
        $where .= ' AND nickname NOT LIKE "%'.$v.'%"';
    }
}
$sql = 'select id as user_id,nickname,avatar,openid from wx_user'. $where;
$users = array();
$db->query( $sql );
$allCount = $db->db_num_rows();
while( $row = $db->fetch_array() ){
    $row['avatar'] = strtr($row['avatar'],array('/64'=>'/132'));
    $users[$row['user_id']] = $row;
}

//内定人员
$prizePersons = $config['prize_persons'];
$prizePersons = !empty( $prizePersons ) ? explode(',',$prizePersons): array();
$cutPersons = array();
if( !empty($prizePersons) ){
    foreach( $prizePersons as $id ){
        $cutPersons[] = $users[$id];
    }
}
?>
<!DOCTYPE HTML>
<html><head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=8">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <title>摇一摇结果</title>
    <link charset="utf-8" rel="stylesheet" href="css/grace.css?v=123" media="all">
    <link charset="utf-8" rel="stylesheet" href="css/time.css" media="all">
    <script src="js/jquery.js"></script>
    <script src="js/time.js?v=<?=rand(1111,9999)?>"></script>
</head>
<body>
<style type="text/css">
    .g-container{background-size: 100% 100%;color: #fff;}
    .btn-wrap{text-align: center;position: absolute;width: 100%;bottom: 5%}
    .btn-wrap .g-button{width: 100px;line-height: 32px;border-radius: .3em}
    .btn-wrap .start{color: #9e1f16}
    .btn-wrap .stop{margin-left: 50px}
    .printbox .reward-wrap{width: 850px;margin: 130px auto}

    .printbox .reward-wrap .reward-item{margin: 0 auto;float: left;text-align: center}
    .printbox .reward-wrap .reward-item img{width: 80%;border-radius: 50%;border:3px solid #c59845;}
    .printbox .reward-wrap .reward-item p{font-size: 18px;font-weight: 500;padding:5px 0 20px;overflow:hidden}

    .printbox .reward-wrap .reward-item{width: 14.2%}


    .printbox .count7{padding-top: 6em}

    .printbox .count6{padding-top: 6em}
    .printbox .count6 .reward-item{width: 16.6%}
    .printbox .count5{padding-top: 4.5em}
    .printbox .count5 .reward-item{width: 20%}

    .printbox .count4{padding-top: 100px}
    .printbox .count4 .reward-item{width: 25%}

    .printbox .count3{padding-top: 70px}
    .printbox .count3 .reward-item{width: 33.3%}

    .printbox .count2, .printbox .count1{padding-top: 60px}
    .printbox .count2 .reward-item, .printbox .count1 .reward-item{width: 50%}
    .printbox .count2 .reward-item img, .printbox .count1 .reward-item img{width: 50%;}
    .printbox .reward-wrap.count2 .reward-item p{font-size: 22px;}

    .printbox .count1 .reward-item{float: none}
    .printbox .reward-wrap.count1 .reward-item  p{font-size: 30px;}
</style>

<div class="g-container">
    <div id="countdown" style="position:absolute;top:40%;left:500px">
        <div class="hold">
            <div class="pie pie1"></div>
        </div>

        <div class="hold">
            <div class="pie pie2"></div>
        </div>

        <div class="bg"> </div>

        <div class="time"><?=$config['prize_speed']?></div>
    </div>
    <div class="g-content">

        <div class="printbox"><div class="reward-wrap count<?=$config['prize_count']?>">
                <ul>
                    <li class="reward-item">
                        <img src="http://wx.qlogo.cn/mmopen/5aqukicJ1rag24PbhMmVibia1Kt3KucWQycn4iaSWWTnCr44hhYkhshCgLKz1fiaVl3aoLSKM80AdaBk3xTia7ZgJnpw/64">
                        <p>***</p></li>
                </ul></div></div>
        <div class="btn-wrap">
            <p id="hideCount" style="color: darkred;"><?=$config['prize_count']?>/<?=$allCount?></p>
            <input type="button" value="开始" class="g-button g-button-red" onclick="startRoll()">
            <!--<input type="button" value="停止" class="g-button stop">-->
        </div>
    </div>
</div>
<div style="display: none">
    <p id="speed">1</p>
    <p id="shake_second"><?=$config['prize_speed']?></p>
    <p id="prize_count"><?=$config['prize_count']?></p>
    <p id="prize_type">0</p>
</div>
</body>
<script src="js/prize.js"></script>
<script>
    (function ($) {
        var h1 = document.documentElement.clientHeight;
        $('.g-container,.g-content').height(h1);
        $('.g-container').css('min-height',window.screen.height);
        var screenWidth = window.screen.width;
        $('#countdown').css('left',(screenWidth-200)/2);
        FX.Prize.init({
            cut_persons:<?=json_encode(array_values( $cutPersons ) )?>,
            users:<?=json_encode(array_values($users))?>});
    }(jQuery));
    setTimeout(function(){
        $('#hideCount').hide();
    },1500);
</script>
</html>

